package fr.mairie.parc.dao.impl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.jdbc.core.JdbcTemplate;

import fr.mairie.parc.dao.DemandeDao;
import fr.mairie.parc.dao.mapper.DemandeRowMapper;
import fr.mairie.parc.domain.Demande;

@Configurable
public class DemandeDaoImpl implements DemandeDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Autowired
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public JdbcTemplate getJdbcTempalete() {
		return jdbcTemplate;
	}

	@Autowired
	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}


	@SuppressWarnings("unchecked")
	@Override
	public List<Demande> selectAll() {
		return jdbcTemplate.query("SELECT idDemande, numParc, marque, modele, date, batiment, etage, salle, direction, service, utilisateur" +
		"" + " FROM demandeprevu",
				new DemandeRowMapper());
	}

	@Override
	public Demande getDemandeById(int id) {
		return (Demande) jdbcTemplate.queryForObject("SELECT * FROM demandeprevu WHERE idDemande=?",
				new Object [] {id},
				new DemandeRowMapper());
	}
}